from tkinter import *
from tkinter import messagebox

root = Tk()
root.geometry('400x400+200+200')
root.title('place方法使用')

# b1 = Button(root,text='B1',bg='red')
# b1.place(x=50,y=50,width=50,height=50)

# b2 = Button(root,text='B1',bg='red')
# b2.place(relx=0.5,rely=0.5,relwidth=0.5,relheight=0.5)

# photo = PhotoImage(file='1.gif')
# b1 = Button(root,image=photo)
# b1.place(x=30,y=200)

# 定义鼠标单击事件,点击一下，扑克向上，再点一下，扑克回来
def chupai(event):   # 记住这个event形参不能少
    # 得到坐标
    zb = event.widget.winfo_geometry()
    # 得到X和Y的坐标
    x1 = event.widget.winfo_x()
    y1 = event.widget.winfo_y()
    print(x1,y1)
    if y1 == 200:
        event.widget.place(y=150)
    else:
        event.widget.place(y=200)


# 列表的简单写法，记得掌握
photos = [PhotoImage(file='%s.gif'%x) for x in range(1,5)]

for p,n in zip(photos,range(1,5)):
    b = Button(root,image=p)
    b.place(x=30*n,y=200)
    b.bind_class('Button','<Button-1>',chupai)   # 将这个鼠标左键的事件绑定在button上

root.mainloop()